//
// Created by Tony on 2024/6/14.
//

#ifndef RUNTIME_INTERPRETER_H
#define RUNTIME_INTERPRETER_H

#include "../../file_reader/SourceFile.h"
#include "../../parser/ast/Ast.h"
#include "../rt_code/ClassTable.h"
#include "../rt_data/Frame.h"
#include <memory>
#include <string>

namespace Runtime {

using std::shared_ptr;
using std::string;

class Interpreter {

public:
    static shared_ptr<RtData::Frame> interpretStatement(
        const shared_ptr<RtCode::ClassTable>& classTable, const string& code);
    static shared_ptr<RtData::Frame> interpretModule(
        const shared_ptr<RtCode::ClassTable>& classTable, const shared_ptr<SourceFile>& sourceFile);
    static shared_ptr<RtData::Frame> interpretClass(
        const shared_ptr<RtCode::ClassTable>& classTable, const shared_ptr<SourceFile>& sourceFile);

private:
    static shared_ptr<RtData::Frame> interpretModule(
        const shared_ptr<RtCode::ClassTable>& classTable, const shared_ptr<Parser::Ast>& ast);
    static shared_ptr<RtData::Frame> interpretClass(
        const shared_ptr<RtCode::ClassTable>& classTable, const shared_ptr<Parser::Ast>& ast);

    static shared_ptr<RtData::Frame> loop(const shared_ptr<RtCode::ClassTable>& classTable);

    static void printDebugInfo(uint32_t pc, uint16_t top, shared_ptr<RtData::Frame> frame);
};

} // namespace Runtime

#endif // RUNTIME_INTERPRETER_H
